//SavageWorldsRaiseRoller.js // // By: Carl Davis // https://app.roll20.net/users/2505097/carl-d (Carl D.) // Email: cdavis AT SIGN webcommando.com (replace AT SIGN with @) // // // This API script performs a Savage Worlds roll (including wild die) and then displays // a list of the target numbers with information on if this roll would be a success and any raises associated with // it. // /* Use this macro as an example of use with an extra !swrr exta ?{Choose Die| d4,4| d6,6| d8,8| d10,10| d12,12} ?{Choose Bonue|0} */ // // var SavageWorldsRaiseRoller = SavageWorldsRaiseRoller || (function() { 'use strict'; var version = '0.1.0', lastUpdate = 1569801600, checkInstall = function() { log('-=> SavageWorldsRaiseRoller v'+version+' <=- ['+(new Date(lastUpdate*1000))+']'); }, // Handle input coming from message handleInput = function(msg) { var args, whisper = false, extra = false, dieType = 6, extraParam = 'extra', bonusAmount = 0, who = msg.who; if (msg.type !== "api") { return; } //log("Message: " + msg.content); args = msg.content.split(/\s+/); switch(args.shift()) { //case 'help': // var helpText = "
Help:
!swrr extra DIE BONUS
DIE is the number of sides of the die (4,6,8,10,12)
BONUS is a numeric bonus to add to die roll.
extra - you can add the optional extra parameter to tell the roller to not use the wild die in the roll.
!wswrr command can be used to whisper to GM with same parameters as above.
Example: !swrr 6 -5 ==> Roll 1d6 with bonus of -5 for a wildcard."
sendChat('', outputString);
},
// Do all the rolling and getting ready.
rollDice = function(dieSides, extra) {
//log ("rollDice");
var maxRoll;
var mainRoll = rollExplodingDie(dieSides);
var wildTotal = rollExplodingDie(6);
//log("Roll:" + mainRoll + "; Wild:" + wildTotal);
// which roll do we take?
if (!extra)
{
maxRoll = Math.max(mainRoll, wildTotal);
} else {
maxRoll = mainRoll;
}
//log ("Max Roll:" + maxRoll);
return (maxRoll);
},
generateOutput = function(theRoll, bonus, dieType, isExtra, who) {
//log ("generateOutput");
var rollString = "